home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cenvid / rmdir.cmm < prev    next >
Encoding:
Text File  |  1995-10-01  |  2.4 KB  |  99 lines

  1. /*
  2.  * rmdir.cmm
  3.  *
  4.  * This .CMM file implements a DOS-like RD command.
  5.  */
  6.  
  7. #include "Netware.lib"
  8.  
  9. usage()
  10. {
  11.   printf("Use the RD command to remove an empty directory.\n");
  12.   printf("Syntax:\n");
  13.   printf("  RD [drive:][path]\n");
  14.   printf("where:\n");
  15.   printf("  drive:/path  Specifies the directory to remove. It must be empty.\n");
  16.   exit(EXIT_FAILURE);
  17. }
  18.  
  19. /* ---------------------------------------------------------------------- */
  20.  
  21. DeleteDirectory(pDirSpec)
  22. {
  23.    lReg.ah = 0x3A;
  24.    if !defined(_DOS32_)
  25.       lReg.ds = segment(pDirSpec), lReg.dx = offset(pDirSpec);
  26.    else
  27.       lReg.dx = pointer(pDirSpec);
  28.    return interrupt(0x21,lReg);
  29. }
  30.  
  31. myrmdir(dir)
  32. {
  33.   if( defined(_NWNLM_) ) return rmdir(dir);
  34.   if( defined(_OS2_) )
  35.     {
  36. #define ORD_DOS32DELETEDIR 226
  37.       return DynamicLink("DOSCALLS",ORD_DOS32DELETEDIR,BIT32,CDECL,dir);
  38.     }
  39.   if( defined(_NTCON_) || defined(_NTWIN_) )
  40.     {
  41.       return !DynamicLink("KERNEL32","RemoveDirectoryA",STDCALL,dir);
  42.     }
  43.   if( defined(_DOS_) || defined(_WINDOWS_) || defined(_DOS32_) )
  44.     {
  45.       return !DeleteDirectory(dir);
  46.     }
  47.  
  48.   printf("Rmdir.cmm does not support this version of CEnvi.\n");
  49.   return 1;
  50. }
  51.  
  52. /* ---------------------------------------------------------------------- */
  53.  
  54. main(argc,argv)
  55. {
  56.   if( argc!=2 ) usage();
  57.   if( !strcmp(argv[1],"/?") ) usage();
  58.  
  59.   source = argv[1];
  60.  
  61.   dest = Directory(source);
  62.   if( dest==NULL )
  63.     {
  64.       if( isalpha(source[0]) && source[1]==':' &&
  65.           (source[2]=='\0' || source[2]=='/' || source[2]=='\\') )
  66.         {
  67.           printf("You may not remove volume \"%s\".\n",source);
  68.         } else {
  69.           printf("There is no directory named \"%s\".\n",source);
  70.         }
  71.       exit(EXIT_FAILURE);
  72.     } else {
  73.       if( GetArraySpan(dest)!=0 )
  74.     {
  75.       printf("You may not specify more than one directory.\n");
  76.       exit(EXIT_FAILURE);
  77.     }
  78.       if( (dest[0].attrib & _A_SUBDIR)==0 )
  79.     {
  80.       printf("\"%s\" is not a directory.\n",source);
  81.       exit(EXIT_FAILURE);
  82.     }
  83.     }
  84.  
  85.   strcpy(tmp,source);
  86.   if( tmp[strlen(tmp)-1]!='/' ) strcat(tmp,"/");
  87.   strcat(tmp,"*.*");
  88.   if( Directory(tmp) )
  89.     {
  90.       printf("\"%s\" cannot be removed; directory not empty.\n",source);
  91.       exit(EXIT_FAILURE);
  92.     }
  93.   if( myrmdir(source) )
  94.     {
  95.       printf("\"%s\" was not removed.\n",source);
  96.     }
  97.   exit(EXIT_SUCCESS);
  98. }
  99.